package com.lanou.controller;

import com.lanou.bean.LayuiJson;
import com.lanou.bean.Permission;
import com.lanou.bean.Role;
import com.lanou.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    //@RequestMapping("/findRole")
    //public ModelAndView findAllRole(ModelAndView modelAndView){
    //    List<Role> roles = roleService.findAllRole();
    //    modelAndView.addObject("roleList",roles);
    //    modelAndView.setViewName("admin-role");
    //    return modelAndView;
    //}

    @RequestMapping("/findRole")
    @ResponseBody
    public LayuiJson<Role> findAllRole(@RequestParam(value = "page", required = false, defaultValue = "1") Integer currentPage,
                                       @RequestParam(value = "limit", required = false, defaultValue = "10") Integer pageSize){
        //List<Role> roles = roleService.findAllRole();
        ////modelAndView.addObject("roleList",roles);
        ////modelAndView.setViewName("admin-role");
        //LayuiJson<Role> roleLayuiJson = new LayuiJson<>();
        //roleLayuiJson.setCode(0);
        //roleLayuiJson.setCount(10L);
        //roleLayuiJson.setMsg("查询成功");
        //roleLayuiJson.setData(roles);
        return roleService.findAllRole(pageSize,currentPage) ;
    }

    @RequestMapping("/deleteRole")
    @ResponseBody
    public String deleteRoleById(Integer id){
        roleService.delteRoleById(id);
        return "删除成功";
    }
    @RequestMapping("/addRole")
    public String addRole(){

        return null;
    }
    @RequestMapping("/sortPermission")
    @ResponseBody
    public Map<Permission, Map<Permission, List<Permission>>> sortPermission(){
        return roleService.sortPermission();
    }

}
